package com.md.api.service.impl;

import cn.hutool.core.date.DateUtil;
import com.md.api.common.utils.CodeUtil;
import com.md.api.common.utils.TokenUtil;
import com.md.api.dao.PhotoInfoMapper;
import com.md.api.dao.TbOrderMapper;
import com.md.api.dao.UserMapper;
import com.md.api.dao.VipPropertiesMapper;
import com.md.api.entity.*;
import com.md.api.entity.dto.ComposeQueryDto;
import com.md.api.entity.util.Page;
import com.md.api.service.VipCenterSevice;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * @Author liujie
 * @ClassName VipCenterServiceImpl
 **/

@Slf4j
@Service
public class VipCenterServiceImpl implements VipCenterSevice {


    @Resource
    VipPropertiesMapper vipMapper;
    @Resource
    TbOrderMapper orderMapper;
    @Resource
    UserMapper userMapper;
    @Resource
    TokenUtil tokenUtil;

    @Override
    public HttpResult list() {
        List<VipProperties> vipList = vipMapper.selectAll();
        return new HttpResult(vipList);
    }

//    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
//    @Override
//    public HttpResult buy(HttpServletRequest request, VipProperties vip) {
//
//        try {
//
//            // 1判定是否重复购买  2下订单 3支付  4用户权限修改
//
//
//            TbOrder order = new TbOrder();
//            //创建订单号
//            String code = CodeUtil.verifyCode(6);
//            String today = DateUtil.format(new Date(), "yyyyMMdd");
//            String orderNo = "sn".concat(today).concat(code);
//            order.setOrderNo(orderNo);
//            String userId = tokenUtil.getUserId(request);
//            order.setUserId(userId);
//            order.setOrderType(1);
//            order.setPayStatus(1);
//            order.setActualPay(vip.getPrice());
//            order.setTotalPay(vip.getPrice());
//            orderMapper.initOrder(order);
//
//            TbOrderDetail detail = new TbOrderDetail();
//            detail.setOrderNo(orderNo);
////            detail.set
//            return HttpResult.OK;
//        }catch (Exception e){
//            e.printStackTrace();
//            return HttpResult.fail("交易失败！");
//        }
//
//    }
}
